package com.stylefeng.guns.modular.pay.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.pay.model.AllinMch;
import com.stylefeng.guns.modular.pay.service.IAllinMchService;

/**
 * 通联配置控制器
 *
 * @author fengshuonan
 * @Date 2018-09-20 11:17:35
 */
@Controller
@RequestMapping("/allinMch")
public class AllinMchController extends BaseController {

    private String PREFIX = "/pay/allinMch/";

    @Autowired
    private IAllinMchService allinMchService;

    /**
     * 跳转到通联配置首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "allinMch.html";
    }

    /**
     * 跳转到添加通联配置
     */
    @RequestMapping("/allinMch_add")
    public String allinMchAdd() {
        return PREFIX + "allinMch_add.html";
    }

    /**
     * 跳转到修改通联配置
     */
    @RequestMapping("/allinMch_update/{allinMchId}")
    public String allinMchUpdate(@PathVariable Integer allinMchId, Model model) {
        AllinMch allinMch = allinMchService.selectById(allinMchId);
        model.addAttribute("item",allinMch);
        LogObjectHolder.me().set(allinMch);
        return PREFIX + "allinMch_edit.html";
    }

    /**
     * 获取通联配置列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return allinMchService.selectList(null);
    }

    /**
     * 新增通联配置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(AllinMch allinMch) {
        allinMchService.insert(allinMch);
        return SUCCESS_TIP;
    }

    /**
     * 删除通联配置
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer allinMchId) {
        allinMchService.deleteById(allinMchId);
        return SUCCESS_TIP;
    }

    /**
     * 修改通联配置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(AllinMch allinMch) {
        allinMchService.updateById(allinMch);
        return SUCCESS_TIP;
    }

    /**
     * 通联配置详情
     */
    @RequestMapping(value = "/detail/{allinMchId}")
    @ResponseBody
    public Object detail(@PathVariable("allinMchId") Integer allinMchId) {
        return allinMchService.selectById(allinMchId);
    }
}
